var c = require("../libs/common.js");
var config = require("../libs/config.js");
var upimg = require('../libs/upimg.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hiddeninfo:true,
    vhidden:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var myDate = new Date();//获取系统当前时间
   var y=  myDate.getFullYear(); //获取完整的年份(4位,1970-????)
   var m=  myDate.getMonth(); //获取当前月份(0-11,0代表1月)
   var d=  myDate.getDate(); //获取当前日(1-31)
   var date=y+'-'+m+'-'+d;
    this.setData({ date: date})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  simpleUpload: function (e) {
    var path = 'feedback/' + new Date().getTime() + '.png';
    var that = this;
    var returninfo = upimg.simpleUpload(
      path,
      function (res) {
        console.log(res);
        that.setData({
          arrayimg: res
        })
      },
      6
    );
  },
  phone:function(e){
    var phone=e.detail.value;
    this.setData({ phone: phone})
  },
  bindinputTextarea:function(e){
    var textare=e.detail.value;
    this.setData({ textare: textare})
  },
  submit:function(){
    var picstring='';
    var arrayimg= this.data.arrayimg;
    var textare = this.data.textare;
    var phone   = this.data.phone;
    for (var i = 0; i < arrayimg.length;i++){
      if (i == arrayimg.length-1){
        picstring += arrayimg[i]['imgLocation']; 
      }else{
        picstring += arrayimg[i]['imgLocation']+',';
      }
    }
    c.ajax(
      config.hostapi +'Feedback/addFeedback',
      { picstring: picstring, textare: textare, phone: phone},
      res=>{
        if (res.data.status == 'success'){
          wx.showToast({
            title: '反馈成功',
            image: '/images/dui.png'
          })
          setTimeout(function(){
            wx.switchTab({
              url: '/pages/my/my',
            })
          },1000)
        };
      }
    )
  }
})